//
//  UIView+DGGPullDownMenuToolBar.m
//  demo
//
//  Created by 周家民 on 2020/8/12.
//  Copyright © 2020 mac. All rights reserved.
//

#import "UIView+DGGPullDownMenuToolBar.h"
#import <objc/runtime.h>

@implementation UIView (DGGPullDownMenuToolBar)

- (void)setOnClick:(ClickBlock)onClick {
    objc_setAssociatedObject(self, "dgg_pulldown_onclick", onClick, OBJC_ASSOCIATION_COPY);
    UITapGestureRecognizer *oldReco = objc_getAssociatedObject(self, "dgg_pulldown_tap");
    if (oldReco) {
        [self removeGestureRecognizer:oldReco];
    }
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)];
    [self addGestureRecognizer:tap];
    objc_setAssociatedObject(self, "dgg_pulldown_tap", tap, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (ClickBlock)onClick {
    return objc_getAssociatedObject(self, "dgg_pulldown_onclick");
}

- (void)onTap {
    if (self.onClick) {
        self.onClick();
    }
}

@end
